﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class GenParse_TransportServiceType
	{
		#region private constants

		private const byte AnalogFixedConnectionByte	= 0x10;		
		private const byte AnalogDynamicConnectionByte	= 0x20;
		private const byte X25_DatexPByte				= 0x30;
		private const byte ISDN_B_ChannelByte			= 0x40;
		private const byte ISDN_D_ChannelByte			= 0x50;
		private const byte TrunkingByte					= 0x60;
		private const byte RadioDataTransmissionByte	= 0x70;
		private const byte MobileRadioCommunicationByte = 0x80;
		private const byte TCP_IP_IntranetByte			= 0x90;
	
		#endregion private constants

		#region internal methods

		internal static byte GenerateByte(eTransportServiceType transportServiceType)
		{
			byte transportServiceTypeByte = 0x00;
			switch (transportServiceType)
			{
				case eTransportServiceType.AnalogFixedConnection:
					transportServiceTypeByte = AnalogFixedConnectionByte;
					break;
				case eTransportServiceType.AnalogDynamicConnection:
					transportServiceTypeByte = AnalogDynamicConnectionByte;
					break;
				case eTransportServiceType.X25_DatexP:
					transportServiceTypeByte = X25_DatexPByte;
					break;
				case eTransportServiceType.ISDN_B_Channel:
					transportServiceTypeByte = ISDN_B_ChannelByte;
					break;
				case eTransportServiceType.ISDN_D_Channel:
					transportServiceTypeByte = ISDN_D_ChannelByte;
					break;
				case eTransportServiceType.Trunking:
					transportServiceTypeByte = TrunkingByte;
					break;
				case eTransportServiceType.RadioDataTransmission:
					transportServiceTypeByte = RadioDataTransmissionByte;
					break;
				case eTransportServiceType.MobileRadioCommunication:
					transportServiceTypeByte = MobileRadioCommunicationByte;
					break;
				case eTransportServiceType.TCP_IP_Intranet:
					transportServiceTypeByte = TCP_IP_IntranetByte;
					break;
				default:
					// TODO handle error (unknown value for transportServiceType)
					break;
			}

			return transportServiceTypeByte;
		}

		internal static bool ParseByte(byte transportServiceTypeByte, out eTransportServiceType transportServiceType)
		{
			// set default value
			bool bRetVal = true;
			transportServiceType = eTransportServiceType.AnalogFixedConnection;

			switch (transportServiceTypeByte)
			{
				case AnalogFixedConnectionByte:
					transportServiceType = eTransportServiceType.AnalogFixedConnection;
					break;
				case AnalogDynamicConnectionByte:
					transportServiceType = eTransportServiceType.AnalogDynamicConnection;
					break;
				case X25_DatexPByte:
					transportServiceType = eTransportServiceType.X25_DatexP;
					break;
				case ISDN_B_ChannelByte:
					transportServiceType = eTransportServiceType.ISDN_B_Channel;
					break;
				case ISDN_D_ChannelByte:
					transportServiceType = eTransportServiceType.ISDN_D_Channel;
					break;
				case TrunkingByte:
					transportServiceType = eTransportServiceType.Trunking;
					break;
				case RadioDataTransmissionByte:
					transportServiceType = eTransportServiceType.RadioDataTransmission;
					break;
				case MobileRadioCommunicationByte:
					transportServiceType = eTransportServiceType.MobileRadioCommunication;
					break;
				case TCP_IP_IntranetByte:
					transportServiceType = eTransportServiceType.TCP_IP_Intranet;
					break;
				default:
					// TODO handle error (unknown value for transportServiceTypeByte)
					bRetVal = false;
					break;
			}

			return bRetVal;
		}

		#endregion internal methods
	}
}
